package com.button.springboothdfsclient.service.impl;

import com.button.springboothdfsclient.conf.HdfsFilesystemConf;
import com.button.springboothdfsclient.service.HdfsService;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @Description
 * @Author Administrator
 * @Date 2023/2/2 13:44
 **/
@Service
public class HdfsServiceImpl implements HdfsService {

    @Autowired
    private HdfsFilesystemConf hdfsFilesystemConf;

    /**
     * 上传
     *
     * @Description 上传
     * @Return void
     * @Author Administrator
     * @Date 2023/2/2 13:45
     **/
    @Override
    public void upload2Hdfs() throws IOException {
        FileSystem fileSystem = hdfsFilesystemConf.hdfsFileSystem();
        Path src = new Path("E:\\文件存储\\个人文件\\图片\\hadoop.jpg");
        Path dst = new Path("/button/hadoop.jpg");
        fileSystem.copyFromLocalFile(src, dst);
    }

    /**
     * 下载
     * @Description  下载
     * @Return void
     * @Author Administrator
     * @Date 2023/2/2 13:51
     **/
    @Override
    public void downloadFromHdfs() throws IOException {
        FileSystem fileSystem = hdfsFilesystemConf.hdfsFileSystem();
        Path src = new Path("/button/hadoop.jpg");
        Path dst = new Path("E://hadoop.jpg");
        fileSystem.copyToLocalFile(src, dst);
    }
}
